﻿package  {
	
	import com.greensock.TweenMax;
	import flash.display.MovieClip;
	import flash.display.StageDisplayState;
	import flash.events.Event;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.sampler.NewObjectSample;
	import flash.utils.Timer;
	import flash.events.TimerEvent;
	
	
	public class Main extends MovieClip {
		
		var ureq:URLRequest;
		var loader:URLLoader;
		private var managerTime:Timer;
		private var arrUrl:Array;
		private var bigUrl:String;
		public static var main:Main;
		public var numPic:int;
		public var bbShowed:Boolean=false;
		public function Main() {
			// constructor code
			main = this;
			this.addEventListener(Event.ADDED_TO_STAGE, addet);
		}
		private function addet(e:Event) {
			getItemName();
			mcWord.gotoAndPlay(2);
			stage.displayState = StageDisplayState.FULL_SCREEN;
		}
		//获取登陆用户
		public function getItemName() {
			//callbackFun = callback;
			
			//var n:Number = new Date().getTime();
			ureq = new URLRequest("http://115.47.49.114/adbaobao/index.php/Index/index/type/0");
			loader=new URLLoader();
			loader.load(ureq);
			loader.addEventListener(Event.COMPLETE,itemnameInfo);
		}
		private function itemnameInfo(evt:Event) {
			arrUrl = new Array;
			var resultXML:XML = new XML(evt.target.data);
			//var demo:Array = [];
			var len:int = resultXML.photosUrl.data.length();
			numPic = len;
			trace("len=", len)
			for (var i:int = 0; i < len; i++ ) {
				arrUrl.push(resultXML.photosUrl.data[i]);
			}
			//mcTest.setUrl(resultXML.photosUrl.data[0]);
			
			managerTime = new Timer(1000, 1);
			managerTime.addEventListener(TimerEvent.TIMER_COMPLETE, subTime);
			managerTime.start();
		}
		private function subTime(evt:TimerEvent) {
			if (arrUrl.length == 0) {
				getTotalPhoto();
				managerTime.start();
				return;
			}
			//trace("subTime")
			Container_mc.addPic(arrUrl.pop());
			//Container_mc.addPic(arrUrl.pop());
			//Container_mc.addPic(arrUrl.pop());
			//Container_mc.addPic(arrUrl.pop());
			managerTime.start();
		}
		//获取大合照
		public function getTotalPhoto() {
			//callbackFun = callback;
			if (!bbShowed) return;
			var n:Number = new Date().getTime();
			ureq = new URLRequest("http://115.47.49.114/adbaobao/index.php/Index/index/type/1?ram="+n);
			loader=new URLLoader();
			loader.load(ureq);
			loader.addEventListener(Event.COMPLETE,itemnameInfo2);
		}
		private function itemnameInfo2(evt:Event) {
			//arrUrl = new Array;
			var resultXML:XML = new XML(evt.target.data);
			//var demo:Array = [];
			//var len:int = resultXML.photosUrl.data.length();
			//trace("mark=", resultXML.mark)
			if (int(resultXML.mark) == 1) {
				managerTime.stop();
				trace(resultXML.photosUrl.data);
				bigUrl = String(resultXML.photosUrl.data);
				var mct:picBig = new picBig();
				mct.setUrl(bigUrl);
				addChild(mct);
				mct.x = -1024 / 2;
				mct.y = 768 / 2;
			}
			
		}
		public function showBigPic() {
			var mcTemp:picLoader = new picLoader();
			mcTemp.setUrl(bigUrl);
			Container_mc.addChild(mcTemp);
			mcTemp.x = PicManager.picmanager.targetX;
			mcTemp.y = PicManager.picmanager.targetY;
			TweenMax.to(mcTop, 3, { alpha:1, delay:10 } );
		}
	}
	
}
